<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <h1>{{msg}}</h1>
        <hr>
        <input type="text" v-model="inputVal">
        <button @click="addData">点击添加数据</button>
        <ul>
            <li v-for="(item,index) of brandList" :key="item.id">
                <span>id:{{item.id}}</span>
                <span>名字:{{item.name}}</span>
                <span>日期:{{item.ctime}}</span>
            </li>
        </ul>
    </div>
    <script src="./js/vue.js"></script>
    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                msg: "Hello Vue!",
                inputVal: "",
                brandList: [{
                        id: 10,
                        name: '奔驰',
                        ctime: new Date()
                    },
                    {
                        id: 11,
                        name: '宝马',
                        ctime: new Date()
                    },
                    {
                        id: 12,
                        name: '奥迪',
                        ctime: new Date()
                    }
                ]
            },
            methods: {
                addData() {
                    if (this.inputVal.trim() != "") {
                        let obj = {
                            id: this.brandList[this.brandList.length - 1].id + 1,
                            name: this.inputVal,
                            ctime: new Date()
                        }
                        this.brandList.unshift(obj);
                    }
                }
            }
        });
    </script>
</body>

</html>